﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Web;

namespace Cybertron_Tracker.Cybertron
{
    public class Issue
    {
        public String project;
        public String name;
        public DateTime date;
        public String content;
        public String link;
        public String id;
        public float loggedHours;

        private DateTime logInit;

        public Issue()
        {
            loggedHours = 0;
        }

        public void setName(String p)
        {
            int nameBegin = p.IndexOf("Feature #") + 8;
            project = Html.Decode( p.Substring(0, nameBegin - 11) );
            name = Html.Decode(p.Substring(nameBegin, p.Length - nameBegin));
        }

        public void setContent(String c)
        {
            content = c;
        }

        public void setDate(String dateString)
        {
            date = DateTime.Parse(dateString);
        }

        public void setLink(String l)
        {
            int beginId = l.IndexOf("/issues/show/") + 13;
            id = l.Substring(beginId, l.Length - beginId);
            link = l;
        }

        public void startLog()
        {
            logInit = DateTime.Now;
        }

        public float endLog()
        {
            TimeSpan diffTime = DateTime.Now - logInit;
            float h = diffTime.Hours;
            float m = diffTime.Minutes;
            float s = diffTime.Seconds;

            loggedHours = (s / 3600) + (m / 60) + h;
            return loggedHours;
        }

        public void clearHours()
        {
            loggedHours = 0;
        }
    }
}
